package com.xiaohei.crm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaohei.crm.common.result.Result;
import com.xiaohei.crm.dao.Material;
import com.xiaohei.crm.service.MaterialService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: MaterialController
 * Package:
 * Description:
 *
 * @Author:xiaohei
 * @Create 2024/6/23 12:54
 * Version 1.0
 */
@RestController
@CrossOrigin
@RequiredArgsConstructor
public class MaterialController {

    private final MaterialService materialService;

    /**
     * 分页查询区域信息
     * @return
     */
    @GetMapping("/material/findByPage")
    public Result<IPage> findByPage(){
        return materialService.findByPage();
    }

    /**
     * 添加用户
     * @param
     * @return
     */
    @PostMapping("/material")
    public Result save(@RequestBody Material material){
        materialService.saveMaterial(material);
        return Result.ok();
    }

    /**
     * 修改区域信息
     * @param
     * @return
     */
    @PutMapping("/material")
    public Result update(@RequestBody Material material){
        materialService.updateMaterialById(material);
        return Result.ok();
    }

    /**
     * 逻辑删除区域
     * @param
     * @return
     */
    @DeleteMapping("material/{id}")
    public Result<String> deleteByUsername(@PathVariable("id") String id){
        materialService.removeByMaterialId(id);
        return Result.ok();
    }

}
